package gsw.demo.pluggable2.binder;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;

import gsw.demo.pluggable.binder.Item1;
import gsw.demo.pluggable.TestAidl;
import gsw.demo.pluggable.binder.Item2;

public class ServiceBinder extends Service {

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new MyStub();
    }

    public static class MyStub extends TestAidl.Stub {
        String name = null;

        @Override
        public String getName() throws RemoteException {
            if (name == null) {
                name = "Hi,Tom";
            }
            return name;
        }

        @Override
        public String setName(String name) throws RemoteException {
            this.name = name;
            return name;
        }

        @Override
        public Item2 getItem2(Item1 item1) throws RemoteException {
            if (item1 != null) {
                item1.name = "I like " + item1.name;
                item1.id++;
                return new Item2(item1);
            }
            return null;
        }
    }
}
